<?php
/**
 *  轮播图模型类
 */
namespace app\admin\model;
use think\Model;
class Slide extends Model
{

    // 获取轮播图列表
    public function getList($UrlParam,$PageCount)
    {
        return $this->order('gid asc,sorting asc,id asc')
				->paginate($PageCount,false,['query' => $UrlParam]);
    }
    // 查找轮播图
    public function findSlide($UrlParam,$PageCount)
    {
		$Where = array();
		if(!empty($UrlParam['field'])) $Where['a.title']=['like','%'.trim($UrlParam['keyword']).'%'];
        return $this
            ->where($Where)
            ->order('gid asc,sorting asc,id asc')
            ->paginate($PageCount,false,['query' => $UrlParam]);
    }

    // 获取轮播图详情
    public function getSlide($id)
    {
        return $this->where("id=$id")
            ->find();
    }

    // 获取分组
    public function getGid()
    {
        return $this->Distinct(true)
            ->order('gid')
            ->column('gid');
    }

    // 获取最大分组值
    public function getMaxGid()
    {
        return $this->max('gid');
    }

    // 添加轮播图
    public function addSlide(array $data)
    {
        return $this->insert($data);
    }

    // 删除轮播图
    public function delSlide($id)
    {
        return $this->where("id=$id")
            ->delete();
    }
    // 修改轮播图
    public function modSlide($id, $data)
    {
        return $this
            ->where("id=$id")
            ->update($data);
    }
}